package org.usmile.algorithms.huawei.acm;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

// https://blog.csdn.net/qq_34465338/article/details/128368670
public class _分奖金 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int[] nums = new int[n];
        String[] numsString = sc.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(numsString[i]);
        }

        int[] rightBigger = new int[n];
        Arrays.fill(rightBigger, -1);

        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < n; i++) {
            while (!stack.isEmpty() && nums[i] > nums[stack.peek()]) {
                rightBigger[stack.pop()] = i;
            }
            stack.push(i);
        }

        int[] result = new int[n];

        for (int i = 0; i < n; i ++) {
            if (rightBigger[i] == -1) {
                result[i] = nums[i];
            } else {
                result[i] = (rightBigger[i] - i) * (nums[rightBigger[i]] - nums[i]);
            }
        }

        System.out.println(Arrays.toString(result));
    }

}
